package com.wanger.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wanger.common.util.ApiResult;
import com.wanger.model.entity.SysResource;
import com.wanger.model.entity.SysUser;
import com.wanger.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: wanger
 * @Date: 2023/8/17 22:17
 * @Description:
 */

@RestController
@Api(value = "用户相关接口", tags = {"用户相关接口"})
@RequestMapping("/sysUser")
public class SysUserController {
    @Resource
    private SysUserService sysUserService;

    @ApiOperation(value = "查询用户列表", notes = "查询用户列表", httpMethod = "POST")
    @PostMapping("/pagingQuery")
    public ApiResult<IPage<SysUser>> pagingQuery(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                 @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize) {
        return new ApiResult<>(sysUserService.page(new Page<>(pageNum, pageSize)));
    }

    @ApiOperation(value = "深翻页测试", notes = "深翻页测试", httpMethod = "POST")
    @PostMapping("/deepPageTurning")
    public ApiResult<IPage<SysResource>> deepPageTurning(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                         @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                                         @RequestParam(value = "name", required = false, defaultValue = "") String name,
                                                         @RequestParam(value = "url", required = false, defaultValue = "") String url) {
        return new ApiResult<>(sysUserService.deepPageTurning(pageNum, pageSize, name, url));
    }

    @ApiOperation(value = "添加用户数据", notes = "添加用户数据", httpMethod = "POST")
    @PostMapping("/addData")
    public ApiResult<Boolean> addData(@RequestBody List<SysUser> userList) {
        return new ApiResult<>(sysUserService.addData(userList));
    }

    @ApiOperation(value = "查询用户详情，一对一查询", notes = "查询用户详情", httpMethod = "POST")
    @PostMapping("queryDetailsV1")
    public ApiResult<SysUser> queryDetailsV1(@RequestParam String id) {
        return new ApiResult<>(sysUserService.queryDetailsV1(id));
    }

    @ApiOperation(value = "查询用户详情，一对多查询", notes = "查询用户资源信息", httpMethod = "POST")
    @PostMapping("/queryDetailsV2")
    public ApiResult<SysUser> queryDetailsV2(@RequestParam String id) {
        return new ApiResult<>(sysUserService.queryDetailsV2(id));
    }

    @ApiOperation(value = "查询用户详情，多对多查询", notes = "分页查询查询用户详情", httpMethod = "POST")
    @PostMapping("/queryDetailsV3")
    public ApiResult<IPage<SysUser>> queryDetailsV3(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                    @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                                    @RequestParam(value = "name", required = false, defaultValue = "") String userName) {
        return new ApiResult<>(sysUserService.queryDetailsV3(pageNum, pageSize, userName));
    }

    @ApiOperation(value = "查询用户详情，多对多查询，不分页时多对多查询演示", notes = "分页查询查询用户详情，不分页时多对多查询演示", httpMethod = "POST")
    @PostMapping("/queryDetailsV3_1")
    public ApiResult<List<SysUser>> queryDetailsV3_1(@RequestBody List<String> userIds) {
        return new ApiResult<>(sysUserService.queryDetailsV3_1(userIds));
    }

    @ApiOperation(value = "查询用户详情，一对一同时一对多查询", notes = "查询用户详情，同时查询用户资源信息", httpMethod = "POST")
    @PostMapping("/queryDetailsV4")
    public ApiResult<SysUser> queryDetailsV4(@RequestParam String id) {
        return new ApiResult<>(sysUserService.queryDetailsV4(id));
    }

    @ApiOperation(value = "查询用户详情，多对多查询用户所有信息", notes = "分页查询用户详细信息与资源信息", httpMethod = "POST")
    @PostMapping("/queryDetailsV5")
    public ApiResult<IPage<SysUser>> queryDetailsV5(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                    @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                                    @RequestParam(value = "name", required = false, defaultValue = "") String userName) {
        return new ApiResult<>(sysUserService.queryDetailsV5(pageNum, pageSize, userName));
    }


}
